<?php

namespace App\Http\Controllers;

use App\Validation\SmsValidation;
use App\Validation\LoginValidation;
use App\Validation\Login3Validation;
use App\Validation\SearchValidation;
use App\Validation\VisitValidation;
use App\Service\UserService;
use App\Service\BillService;
use App\Service\DataService;
use App\Service\DicsService;
use Elasticsearch\ClientBuilder;
use EasyWeChat\Payment\Order;
use App\Service\OssService;

class CommonController extends BaseController
{
    public function loginAction()
    {
		//验证数据
		$raw = $this->validation(new LoginValidation,$this->request->getJsonRawBody());
		$sms_code = $this->redis->get("SMS_CODE_{$raw->mobile}");

		if($raw->code != $sms_code){
			//return $this->echoJson('sms code is not correct',401);
		}
		$user = UserService::getMobileInfo($raw->mobile);
		$session = $this->session;
		$session->set('sub', $user);
		//删除SMS_CODE
		$this->redis->delete("SMS_CODE_{$raw->mobile}");
		//写入数据库
		if(!$this->redis->sIsMember('EWZJ_USERS', $raw->mobile)){
			$this->redis->sAdd('EWZJ_USERS', $raw->mobile);
			//PUSH
			/*$this->queue->put(json_encode([
				"command" => "NEW_USER",
				'id'=>1,
				'mobile'=> $raw->mobile
			]));*/
		}

		return $this->echoJson(['xtoken'=>$session->write()]);
    }

	//第三方登录验证
    public function login3Action()
    {
		$raw = $this->validation(new Login3Validation,$this->request->getJsonRawBody());
		$login3 = new \App\Util\Login3;
		$user = UserService::getLogin3Info($raw->open_id);
        $ok = false;

		if(empty($user->member_id)){
			switch($raw->origin){
				case "qq":
					$app_id = '101387766';//$raw->form == 'android' ? '101387766' : '1105577178';
					$app_key = 'adfc28f90aa0c26ce64aa2459181eaf1';//$raw->form == 'android' ? 'J6QvtrQdJXFR6aoB' : 'sj1H0G6u4muSidij';
					$_rep = $login3->qq($raw->open_id, $raw->token, $app_id, $app_key);
					$rep = json_decode($_rep);
					if($rep->ret == -1){
						$this->echoJson($rep->msg,401);
					}
					$user->nickname = $raw->nickname = $rep->nickname;
                    $user->avatar = $raw->avatar = $rep->figureurl;
                    $ok = true;
					break;
				case "weixin":
					$rep = $login3->weixin($raw->open_id, $raw->token);
                    $rep = json_decode($rep);

                    if(isset($rep->errcode)){
                        $this->echoJson($rep->errmsg,401);
                    }
                    $user->nickname = $raw->nickname = $rep->nickname;
                    $user->avatar = $raw->avatar = $rep->headimgurl;
                    $ok = true;
					break;
				case "weibo":
					break;
			}
            //插入数据库
            if($ok){
                $user->mobile = '';
                $user->role_id = 1;
                $user->member_id = UserService::login3Save($raw);
            }
		}

		$session = $this->session;
		$session->set('sub', $user);

		return $this->echoJson(['xtoken'=>$session->write()]);
    }

	//发送短信
    public function smsAction()
    {
		//验证数据
		$raw = $this->validation(new SmsValidation,$this->request->getJsonRawBody());
		$random = mt_rand(1000,9999);
		$sms_content = '【易屋之家】您好，您本次的短信验证码' . $random;
		$sms_account = '8a48b551501216950150147367f00819';
		$sms_unix = date("YmdHis");
		$sms_sig = strtoupper(md5("{$sms_account}a2c951e740bc4885ba62deb267362112{$sms_unix}"));

		$url = "https://app.cloopen.com:8883/2013-12-26/Accounts/{$sms_account}/SMS/TemplateSMS?sig={$sms_sig}";
		$sms_header = ['Authorization: ' . base64_encode("{$sms_account}:{$sms_unix}")];
	    $rep = $this->f->postJsonCurl($url,['to'=>$raw->mobile,'appId'=>'8aaf07085635aae5015649c82c270b77','templateId'=>183878,'datas'=>[$random,"5分钟"]],$sms_header);
		$rep_result = new \stdClass();
        $rep_result->statusCode = "000000";
        $rep_result->statusMsg = "";
        try {
           $rep_result = json_decode($rep);
        } catch (Exception $e) {
            $this->echoJson("Not Josn Format!",401);
        }
        if($rep_result->statusCode != "000000"){
            //$rep_result->statusMsg
            $this->echoJson("SMS Server Error",401);
        }
		//发送成功  写入验证码有效期
		if($this->redis->exists("SMS_CODE_{$raw->mobile}")){
			return $this->echoJson('sms verification code is not effective',401);
		}
		$this->redis->set("SMS_CODE_{$raw->mobile}", $random);
		$this->redis->expireAt("SMS_CODE_{$raw->mobile}", time() + 60*5);
		$this->queue->put(json_encode([
			"command" => "SMS",
			'content' => $sms_content,
			'code' => $random,
			'mobile'=> $raw->mobile
		]));

		return $this->echoJson('ok');
    }

	//上传
	public function uploadAction()
    {
        $this->getUser();
		$mode = $this->request->getPost("mode");
        $pics_ext_arr = ['jpg','jpeg','png','tiff','bmp','gif'];

        if ($this->request->hasFiles()) {
            $files = $this->request->getUploadedFiles();
            $file_paths[] = "uploads/".date("Y/m/d/");
            $file_paths[] = "uploads/files/".date("Y/m/d/");
            $file_name = md5(uniqid());
            
            /*foreach($file_paths as $file_path){
                if(!is_dir($file_path)) mkdir($file_path,0755,true);
            }*/
            $oss = new OssService;
            $files_path = [];
            foreach ($files as $file) {
                $ext = $file->getExtension();
                $oss_obj = in_array(strtolower($ext), $pics_ext_arr) ? "{$file_paths[0]}{$file_name}.{$ext}" : "{$file_paths[1]}{$file_name}.{$ext}";
                $files_path[] = $oss->uploadFile($file->getTempName(), $oss_obj);
                
            }

            $this->queue->put(json_encode([
                "command" => "UPLOAD",
                'mode' => $mode,
                'images' => $files_path,
                'member_id' => $this->user->member_id
            ]));
            return $this->echoJson($files_path);
        }

		return $this->echoJson('Files Not Find',401);
    }

    public function searchAction()
    {
        $elastic = ClientBuilder::create()->setHosts(["{$this->config->es->host}:{$this->config->es->port}"])->build();
        $raw = $this->validation(new SearchValidation, $this->request->getJsonRawBody());
        
        $type = [1=>'house_new',8=>'house_seco',9=>'house_rent'];
        $vists = [1=>'LP_NEW',8=>'LP_SECO',9=>'LP_RENT'];
        $urls = [1=>'/lp/',2=>'/news/',3=>'/deco/',4=>'/data/',5=>'//', 6=>'/video/',7=>'/deco-com/',8=>'/ershoufang/', 9=>'/zufang/' ,10 =>'/yuanchuang'];
        $type_flip = array_flip($type);
        $types = empty($raw->groupId) || $raw->groupId == -1 ? implode(",",$type) : $type[$raw->groupId];
        $city_name = $this->redis->hGet('REGION_CITY', $this->city_id);
        $area_name = $this->redis->hGet('REGION_AREA', $raw->areaId);
        $raw->words = trim(str_replace($city_name,'',$raw->words));
        if($area_name){
            $raw->words = trim(str_replace($area_name,'',$raw->words));
        }
        
        if(isset($raw->tx) && $raw->tx == 'off'){
            //file_put_contents('./TX.txt','1' . PHP_EOL,FILE_APPEND);
            $this->queue->put(json_encode([
                "command" =>"OFF",
                'add_time'=>time(),
                'page_num' => $raw->page_num,
                'groupId' => $raw->groupId
            ]));
        }
        

        $words = [];
        //均价范围
        $es_price=[];
        
        preg_match_all("/(\d*)(-){0,1}(\d*)元(\/㎡|\/月){0,2}(以上|以下){0,1}\s{0,1}/i",$raw->words,$r,PREG_SET_ORDER);
        if(isset($r[0])){
            $up = $r[0];
            $es_price['gte'] = $up[1];
            $es_price['lte'] = empty($up[3]) ? $up[1] : $up[3];
            if(@$up[5]=="以上"){
                unset($es_price['lte']);
            }
            if(@$up[5]=="以下"){
                unset($es_price['gte']);
            }
            $raw->words = trim(str_replace($up[0],"",$raw->words));
            $words[] = ['range'=>["es_price"=>$es_price]];
        }
        //面积范围
        $es_area = [];
        preg_match_all("/(\d*)(-){0,1}(\d*)㎡(以上|以下){0,1}\s{0,1}/i",$raw->words,$r,PREG_SET_ORDER);
        if(isset($r[0])){
            $areas = [];
            foreach($r as $v){
               $areas[] =  $v[1];
               $areas[] =  $v[3];
               $raw->words = trim(str_replace($v[0],"",$raw->words));
            }
            $es_area['gte'] = min($areas);
            $es_area['lte'] = max($areas);
            if(empty($es_area['gte'])){
                unset($es_area['gte']);
            }
            if(empty($es_area['lte'])){
                unset($es_area['lte']);
            }
            
            $words[] = ['range'=>["es_min_area"=>$es_area]];
            $words[] = ['range'=>["es_max_area"=>$es_area]];
        }
        
        //总价范围
        $es_total_price=[];
        preg_match_all("/(\d*)(-){0,1}(\d*)万(以上|以下){0,1}\s{0,1}/i",$raw->words,$r,PREG_SET_ORDER);
        if(isset($r[0])){
            $tps = [];
            foreach($r as $v){
               $tps[] =  $v[1];
               $tps[] =  $v[3];
               $raw->words = trim(str_replace($v[0],"",$raw->words));
            }
            $es_total_price['gte'] = min($tps);
            $es_total_price['lte'] = max($tps);
            if(empty($es_total_price['gte'])){
                unset($es_total_price['gte']);
            }
            if(empty($es_total_price['lte'])){
                unset($es_total_price['lte']);
            }
            if(!empty($es_total_price))
                $words[] = ['range'=>["es_total_price"=>$es_total_price]];
        }
        
        $_words = explode(' ',$raw->words);
        $raw->words = implode(' ',$_words);
        $hx = ["一室","二室","三室","四室","五室","五室以上"];
        $reqjhx = implode(' ',array_intersect($hx,$_words));
        $raw->words = trim(str_replace($reqjhx,"",$raw->words));
        
        if(!empty($reqjhx)){
            $words[]=['match'=>['words'=>['query'=>$reqjhx]]];
        }
        if(!empty($raw->words)){
            $words[]=['match'=>['words'=>['query'=>$raw->words,'operator'=>'and']]];
        }
        $words[]=['match'=>['city_id'=>['query'=>$this->city_id,'operator'=>'and']]];
        $params = [
            'index' => 'ewfangs',
            'type' => $types,
            'from'=>($raw->p - 1) * $raw->page_num,
            'size'=> $raw->page_num,
            'body' => [
                'query' => [
                    "bool"=>[
                        'must'=>$words,
                        //'should'=>$should
                    ]
                ],
                'sort'=>['_script'=>['type'=>'number','script'=>['inline'=>"Long.parseLong(doc[\"id\"].value)"],'order'=>'desc']]
            ]
        ];
        if(isset($raw->areaId) && $raw->areaId > 0){
            $params['body']['query']['bool']['must'][] = [
                    "match_phrase"=>["region_id"=>['query'=>$raw->areaId]]
                ];
        }
        /*if(isset($raw->tx) && $raw->tx == 'off'){
            $params['body']['query']['bool']['must'][] = [
                    "match_phrase"=>["sources"=>['query'=>"安居客"]]
                ];
        }*/
        //print_r(json_encode($params));exit;
        $results = $elastic->search($params);
        //print_r($results);exit;
        $total = $results['hits']['total'];
        $list = [];
        $http = $this->config->gourl;
        $group_id = $raw->groupId;
        foreach($results['hits']['hits'] as $item){
            if(empty($raw->groupId)){
                $group_id = $type_flip[$item['_type']];
                //$item['_source']['is_collect'] = 0;
            }
            $item['_source']['groupId'] = $group_id;
            //$item['_source']['visit'] = (int)$this->redis->hGet($vists[$group_id],$item['_source']['id']);
            $item['_source']['go_url'] = "{$http}{$urls[$group_id]}{$item['_source']['id']}";
            unset($item['_source']['es_area']);
            unset($item['_source']['es_price']);
            unset($item['_source']['es_min_area']);
            unset($item['_source']['es_max_area']);
            unset($item['_source']['es_total_price']);
            $item['_source']['lon'] = $item['_source']['location']['lon'];
            $item['_source']['lat'] = $item['_source']['location']['lat'];
            unset($item['_source']['words']);
            unset($item['_source']['location']);
            if(!isset($item['_source']['region'])){
                $item['_source']['region'] = '';
            }
            if(isset($raw->tx) && $raw->tx == 'off'){
                //$item['_source']['three_url'] = '';
            }
            
            $list[] = $item['_source'];
        }

        return $this->echoJson(['total'=>$total,'list'=>$list]);
    }



    //下订单
    public function payOrderAction()
    {
        $this->getUser();
        $raw = $this->request->getJsonRawBody();
        $raw->id = isset($raw->id) ? $raw->id : 0;
        $raw->pay = isset($raw->pay) ? $raw->pay : 'weixin';
        $raw->order = isset($raw->order) ? $raw->order : 'report';

        $shop_info = DataService::getInfo($raw->id);
        if(!$raw->id || !$shop_info->id){
            $this->echoJson("not find order data",401);
        }

        if((float)$shop_info->price <= 0){
            $this->echoJson("not pay",401);
        }

        $attributes = [
            'trade_type'       => 'APP',
            'body'             => $shop_info->title,
            'detail'           => '数据报告',
            'out_trade_no'     => date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT),
            'total_fee'        => floatval($shop_info->price) * 10 * 10
        ];

        $order = new Order($attributes);

        $result = $this->pay->payment->prepare($order);

        if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS'){
            $bill = new \stdClass;
            $bill->bn = $order->out_trade_no;
            $bill->member_id = $this->user->member_id;
            $bill->data_id = $shop_info->id;
            $bill->bill_name = $shop_info->title;
            $bill->amount = floatval($shop_info->price);
            $bill->pay_code = $raw->pay;
            $bill->bill_type = 2;
            BillService::save($bill);
            $prepayId = $result->prepay_id;
            $config = $this->pay->payment->configForAppPayment($prepayId);
            $this->echoJson($config);
        }

        $this->echoJson($result->return_msg,401);
    }

    //支付回调
    public function payNotifyAction(){

        $response = $this->pay->payment->handleNotify(function($notify, $successful){
            $this->logger->info(json_encode($notify));
            $order = BillService::getBnInfo($notify->out_trade_no);
            if ($successful) {
                $order->pay_time = date('Y-m-d H:i:s',time());
                $order->state = 2;
                $order->save();
                return true;
            }
        });

        return $response;
    }

    //测试推送
    public function testAction(){
        $model = "iPhone SE 7";
        $message = array (
             'title' => '易屋之家',
             'description' => "内容！！！testset",
             'url'=>"http://baidu.com"
         );

         $opts = array (
             'msg_type' => 1
         );

        if(strpos($model,'iPhone') !== false){
            $this->push->setApiKey('9uusTQW535ZrMWGuRzQ38CFPNccNhuYk');
            $this->push->setSecretKey('m4Mn8g6XOMj4kZUZfLGCKmu5E2DsGmvO');
            $this->push->setDeviceType(4);
            $message = [
                'aps' => [
                    'alert' => $message['description']
                ],
                'title' => $message['title'],
                'go_url'=>$message['url'],
                'groupId'=>1
            ];
            $opts['deploy_status'] = 1;
        }

        $channel_id = "5195164000976476986";
        $r = $this->push->pushMsgToSingleDevice($channel_id, $message, $opts);
        if(!$r){
            print_r($this->push->getLastErrorCode());
            print_r("<br>");
            print_r($this->push->getLastErrorMsg());
        }
        print_r($r);
        exit;
    }
    
    //缓存城市id
    public function cacheReAction(){
        $p = new \stdClass;
        $p->is_group= -1;
        $rows = DicsService::getGroup($p);
        
        foreach($rows as $row){
            $this->redis->hSet('REGION_CITY', $row['id'], $row['city']);
            $params = new \stdClass;
            $params->id = $row['id'];
            $errows = DicsService::getGroup($params,true);
            foreach($errows as $errow){
                $this->redis->hSet('REGION_AREA', $errow['id'], $errow['city']);
            }
        }
        exit('OK'.PHP_EOL);
        
    }
    
    public function versionAction(){

        $this->echoJson(['ver'=>'1.0.0','url'=>'http://h5.15miwo.cn/download']);
    }

    /**
     * [visitAction 通过go_url产生浏览记录]
     * @return [type] [description]
     */
    public function  visitAction()
    {
        $this->getUser(0);

        $raw = $this->validation(new VisitValidation, $this->request->getJsonRawBody());
        // if (!property_exists($raw,'member_id') || !$raw->member_id)
        //     return $this->echoJson('ok');

        $gourl = $this->config->gourl;
        $url  = str_replace($gourl, '', $raw->go_url);
        $url_arr = explode('/',$url);

        if (count($url_arr) < 3)
            return $this->echoJson('ok');

        $group = trim($url_arr[1]);
        $detail_id = intval($url_arr[2]);
        if (!$group || $detail_id <= 0)
            return $this->echoJson('ok');

        $table_urls     = [$gourl,'lp','news','deco','data','','video','comp','ershoufang','zufang','yuanchuang'];
        $urls           = ['urls',  'house', 'news', 'deco', 'data', 'comment', 'video', 'deco-comp', 'house-seco', 'house-rent', 'news-orig'];
        if (!in_array($group, $table_urls))
            return $this->echoJson('ok');

        $urli = str_replace($table_urls, $urls, $group);
        $uri  = '/' . $urli . '/' . 'detail' . '/' . $detail_id;

        $this->queue->put(json_encode([
            "command" => "REQ",
            'city_id' => $this->request->getHeader('City-Id'),
            'channel_id' => $this->request->getHeader('Channel-Id'),
            'uri' => $uri,
            'raw'=> $this->request->getJsonRawBody(),
            'sub'=> $this->session->get('sub')
        ]));

        return $this->echoJson('ok');
    }

    public function search2Action()
    {
        $elastic = ClientBuilder::create()->setHosts(["{$this->config->es->host}:{$this->config->es->port}"])->build();
        $raw = $this->validation(new SearchValidation, $this->request->getJsonRawBody());
        $type = [1=>'house_new',8=>'house_seco',9=>'house_rent'];
        $vists = [1=>'LP_NEW',8=>'LP_SECO',9=>'LP_RENT'];
        $urls = [1=>'/lp/',2=>'/news/',3=>'/deco/',4=>'/data/',5=>'//', 6=>'/video/',7=>'/deco-com/',8=>'/ershoufang/', 9=>'/zufang/' ,10 =>'/yuanchuang'];
        $type_flip = array_flip($type);
        $types = empty($raw->groupId) || $raw->groupId == -1 ? implode(",",$type) : $type[$raw->groupId];
        $city_name = $this->redis->hGet('REGION_CITY', $this->city_id);
        $area_name = $this->redis->hGet('REGION_AREA', $raw->areaId);
        $raw->words = trim(str_replace($city_name,'',$raw->words));
        if($area_name){
            $raw->words = trim(str_replace($area_name,'',$raw->words));
        }

        $words = [];
        //均价范围
        $es_price=[];
        
        preg_match_all("/(\d*)(-){0,1}(\d*)元(\/㎡|\/月){0,2}(以上|以下){0,1}\s{0,1}/i",$raw->words,$r,PREG_SET_ORDER);
        if(isset($r[0])){
            $up = $r[0];
            $es_price['gte'] = $up[1];
            $es_price['lte'] = empty($up[3]) ? $up[1] : $up[3];
            if(@$up[5]=="以上"){
                unset($es_price['lte']);
            }
            if(@$up[5]=="以下"){
                unset($es_price['gte']);
            }
            $raw->words = trim(str_replace($up[0],"",$raw->words));
            $words[] = ['range'=>["es_price"=>$es_price]];
        }
        //面积范围
        $es_area = [];
        preg_match_all("/(\d*)(-){0,1}(\d*)㎡(以上|以下){0,1}\s{0,1}/i",$raw->words,$r,PREG_SET_ORDER);
        if(isset($r[0])){
            $areas = [];
            foreach($r as $v){
               $areas[] =  $v[1];
               $areas[] =  $v[3];
               $raw->words = trim(str_replace($v[0],"",$raw->words));
            }
            $es_area['gte'] = min($areas);
            $es_area['lte'] = max($areas);
            if(empty($es_area['gte'])){
                unset($es_area['gte']);
            }
            if(empty($es_area['lte'])){
                unset($es_area['lte']);
            }
            
            $words[] = ['range'=>["es_min_area"=>$es_area]];
            $words[] = ['range'=>["es_max_area"=>$es_area]];
        }
        
        //总价范围
        $es_total_price=[];
        preg_match_all("/(\d*)(-){0,1}(\d*)万(以上|以下){0,1}\s{0,1}/i",$raw->words,$r,PREG_SET_ORDER);
        if(isset($r[0])){
            $tps = [];
            foreach($r as $v){
               $tps[] =  $v[1];
               $tps[] =  $v[3];
               $raw->words = trim(str_replace($v[0],"",$raw->words));
            }
            $es_total_price['gte'] = min($tps);
            $es_total_price['lte'] = max($tps);
            if(empty($es_total_price['gte'])){
                unset($es_total_price['gte']);
            }
            if(empty($es_total_price['lte'])){
                unset($es_total_price['lte']);
            }
            if(!empty($es_total_price))
                $words[] = ['range'=>["es_total_price"=>$es_total_price]];
        }
        
        $_words = explode(' ',$raw->words);
        $raw->words = implode(' ',$_words);
        $hx = ["一室","二室","三室","四室","五室","五室以上"];
        $reqjhx = implode(' ',array_intersect($hx,$_words));
        $raw->words = trim(str_replace($reqjhx,"",$raw->words));
        
        if(!empty($reqjhx)){
            $words[]=['match'=>['words'=>['query'=>$reqjhx]]];
        }
        if(!empty($raw->words)){
            $words[]=['match'=>['words'=>['query'=>$raw->words,'operator'=>'and']]];
        }
        $words[]=['match'=>['city_id'=>['query'=>$this->city_id,'operator'=>'and']]];
        $params = [
            'index' => 'ewbignews_v1',
            'type' => $types,
            'from'=>($raw->p - 1) * $raw->page_num,
            'size'=> $raw->page_num,
            'body' => [
                'query' => [
                    "bool"=>[
                        'must'=>$words,
                        //'should'=>$should
                    ]
                ],
                'sort'=>['_script'=>['type'=>'number','script'=>['inline'=>"Long.parseLong(doc[\"id\"].value)"],'order'=>'desc']]
            ]
        ];
        if(isset($raw->areaId) && $raw->areaId > 0){
            $params['body']['query']['bool']['must'][] = [
                    "match_phrase"=>["region_id"=>['query'=>$raw->areaId]]
                ];
        }
        //print_r(json_encode($params));exit;
        $results = $elastic->search($params);
        //print_r($results);exit;
        $total = $results['hits']['total'];
        $list = [];
        $http = $this->config->gourl;
        $group_id = $raw->groupId;
        foreach($results['hits']['hits'] as $item){
            if(empty($raw->groupId)){
                $group_id = $type_flip[$item['_type']];
                //$item['_source']['is_collect'] = 0;
            }
            $item['_source']['groupId'] = $group_id;
            //$item['_source']['visit'] = (int)$this->redis->hGet($vists[$group_id],$item['_source']['id']);
            $item['_source']['go_url'] = "{$http}{$urls[$group_id]}{$item['_source']['id']}";
            unset($item['_source']['es_area']);
            unset($item['_source']['es_price']);
            unset($item['_source']['es_min_area']);
            unset($item['_source']['es_max_area']);
            unset($item['_source']['es_total_price']);
            $item['_source']['lon'] = $item['_source']['location']['lon'];
            $item['_source']['lat'] = $item['_source']['location']['lat'];
            //unset($item['_source']['words']);
            unset($item['_source']['location']);
            if(!isset($item['_source']['region'])){
                $item['_source']['region'] = '';
            }
            $list[] = $item['_source'];
        }

        return $this->echoJson(['total'=>$total,'list'=>$list]);
    }
    
    public function wordsAction(){
        header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT', true, 200);
        header('ETag: "5816f349-19"');
        $words = ["一室一厅","二室一厅"];
        exit(implode(PHP_EOL,$words));
    }
    
    public function stopWordsAction(){
        header('Last-Modified: '.gmdate('D, d M Y 10:23:11', time()).' GMT', true, 200);
        header('ETag: "5816f349-19"');
        $words = ["厅"];
        exit(implode(PHP_EOL,$words));
    }    

}
